#include<bits/stdc++.h>
#define all(a) a.begin(), a.end()
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

//std::mt19937 rng {std::chrono::steady_clock::now().time_since_epoch().count()};


int main() {

    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int n, m;
    std::cin >> n >> m;
    std::vector<i64> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }

    std::map<int, int> cnt;
    i64 ans = 0;
    std::vector<i64> pre(n + 1);
    for(int i = 0; i < n; i++) {
        pre[i + 1] = pre[i] + a[i];
    }

    for(int i = 0, j = 0; i < n; i++) {
        ans += cnt[(pre[i] - pre[n] % m + m) % m];
        ans += cnt[pre[i] % m]++;
    }
    std::cout << ans;




    return 0;
}